package typedef

import (
	"time"
)

type PubSubServer interface {
	GetPubConfig() interface{}
	GetSubConfig() interface{}
	NewPublisher(name string, config interface{}, topic string) bool              //新建发布
	Publish(name string, message string) bool                                     //发布信息
	DeferredPublish(name string, message string, delay time.Duration) bool        //延时发布
	DelPublisher(name string) bool                                                //删除发布
	NewSubscriber(name string, config interface{}, topic string) bool             //新建订阅器
	AddSubscriber(channel string, name string, handel MessageHandle) bool         //订阅
	RemoveSubscriber(channel string, name string) bool                            //取消订阅
	DelSubscriber(name string) bool                                               //删除订阅器
	Request(name string, message interface{}, timeout time.Duration) ResponseData //发起请求
	AddReply(name string, handel ReplyHandle) bool                                //添加请求处理
	RemoveReply(name string) bool                                                 //移除请求处理
}

type MessageHandle interface {
	Praise(v []byte) (interface{}, bool)
	Process(data interface{}) error
}

type ReplyHandle interface {
	Praise(v interface{}) (interface{}, bool)
	Process(data interface{}) (interface{}, error)
}

type RequestData struct {
	Topic string
	ReqID string
	Data  interface{}
}

type ReplyData struct {
	Topic string
	ReqID string
	Error bool
	Data  interface{}
}

type ResponseData struct {
	Error   bool
	Message string
	Data    interface{}
}

type GCConfig struct {
	Enable bool
	Tick   time.Duration
}

//通用消息
type CommonMsg struct {
	Sender   string
	SendTime time.Time
	Receiver string
	MsgType  string
	Message  interface{}
}

type CommonMsgConfig struct {
	Handle func(map[string]interface{}) (map[string]interface{}, error)
	Sub    CommonMsgCheck
	Pub    CommonMsgCheck
}
type CommonMsgCheck struct {
	Sender   string
	Receiver string
}

//命令操作模式
//MsgType CommandRequest
type CommandRequest struct {
	Cmd   string
	ReqID string
	Args  map[string]interface{}
}

//MsgType CommandResponse
type CommandResponse struct {
	ReqID    string
	Response map[string]interface{}
}

//计算节点模式
//MsgType ComputeRequest
type ComputeRequest struct {
	ReqID   string
	Request map[string]interface{}
}

type ComputeData struct {
	ReqID string
	Name  string
	Data  interface{}
}

//MsgType ComputeResponse
type ComputeResponse struct {
	ReqID    string
	Response map[string]interface{}
}

type MsgReceiver struct {
	Handle  string
	Stamp   time.Time
	Mutex   bool
	TimeOut time.Duration
}

type ReplyMsgData struct {
	Method string
	Data   interface{}
}

type ComInfo struct {
	Info       ModuleInfo `json:"info"`
	LastUpdate time.Time          `json:"lastupdate"`
}
